package com.thermofisher.dsc.amanda.security.handler;

import com.thermofisher.dsc.amanda.security.model.SecurityUserDetails;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

/**
 * Created by wenjie.yang on 1/3/2019.
 */
@Slf4j
@Component
public class MyLoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

  @Override
  public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
    SecurityUserDetails userDetails = (SecurityUserDetails) authentication.getPrincipal();
    log.info("USER : " + userDetails.getUsername() + " LOGIN SUCCESS !  ");
    super.onAuthenticationSuccess(request, response, authentication);
  }

}
